/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.permission.controller;

import java.util.ArrayList;
import java.util.List;
import queenb.net.entitybean.Q050;
import queenb.web.controller.QueenbController;
import queenb.web.crm.store.CustomerStore;
import queenb.web.permission.store.Q050Store;
import queenb.web.util.ContextUtil;

/**
 *
 * @author VANANH
 */
public class Q050Controller extends QueenbController {

    private String action;
    private int value = 0;
    private int FN100;
    public Q050Store store = new Q050Store();
    private List<Q050> list = new ArrayList<Q050>();
    private String idSearch;

    public Q050Controller() {
        searchAlpha();
        Object act = getRequest().getParameter("action");
        Object val = getRequest().getParameter("value");
        if (act != null && val != null) {
            String[] arr = val.toString().split("--");
            FN100 = Integer.parseInt(arr[0]);
            value = Integer.parseInt(arr[1]);
            action = act.toString();
        }
        
        getKapiMenu().setAdmin(true);
        getKapiMenu().setMainmenu2("m223");

        System.out.println("----------->" + FN100 + action + value);
    }

    public void admin() {
        store.updateColumnOfTable(null, "Q050", "QN057", value, "FN100", FN100, getLogin().getUserName());
    }

    public void deleteAdmin() {
    }

    public void activeUser() {

        store.updateColumnOfTable(null, "Q050", "QN056", value, "FN100", FN100, getLogin().getUserName());

    }

    public void supperAdmin() {

        store.updateColumnOfTable(null, "Q050", "QN055", value, "FN100", FN100, getLogin().getUserName());
        System.out.println("----------->" + FN100 + action + value);
    }

    /**
     * @return the action
     */
    public String getAction() {
        if (action.equals("supperadmin")) {
            supperAdmin();
        } else if (action.equals("active")) {
            activeUser();
        } else if (action.equals("admin")) {
            admin();
        }
        return action;
    }

    public void searchAlpha() {
        try {
            setIdSearch(ContextUtil.getRequestParameter("idSearch"));
            if (getIdSearch() != null && getIdSearch().contains("ALL")) {
                setIdSearch(null);
            }
            getLogin().setCharacter(getIdSearch());
        } catch (Exception ex) {
            setIdSearch("ALL");
        }

    }

    /**
     * @param action the action to set
     */
    public void setAction(String action) {
        this.action = action;
    }

    /**
     * @return the value
     */
    public int getValue() {
        return value;
    }

    /**
     * @param value the value to set
     */
    public void setValue(int value) {
        this.value = value;
    }

    /**
     * @return the list
     */
    public List<Q050> getList() {
        try {
            list = store.ListOfTabQ0050(getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getCharacter(), getLogin().getUserName());
        } catch (Exception ex) {
            System.out.println("---->" + ex.getMessage());
        }
        System.out.println("---->" + list.size());
        return list;
    }

    /**
     * @param list the list to set
     */
    public void setList(List<Q050> list) {
        this.list = list;
    }

    /**
     * @return the idSearch
     */
    public String getIdSearch() {
        return idSearch;
    }

    /**
     * @param idSearch the idSearch to set
     */
    public void setIdSearch(String idSearch) {
        this.idSearch = idSearch;
    }
}
